import React, { Component } from 'react';
import { getComlist } from '../../api/home'
import { withRouter } from 'react-router-dom';
import '../../styles/Recommend.css'
class Recommend extends Component {
    constructor(props) {
        super(props)
        this.state = {
            tlist: []
        }
    }
    componentDidMount() {
        //推荐列表
        getComlist({ page: '1', count: '10' }).then((res) => {
            // console.log(res.data.list);
            this.setState({
                tlist: res.data.list
            })
        })
    }
    //跳转详情页
    godetail(id){
        this.props.history.push('/detail/'+id)
    }

      render() {
        return (
            <div className='recommend'>
                {
                    this.state.tlist.map((item, index) => {
                        return (
                            <div className="itembox" key={item.id} onClick={()=>{this.godetail(item.id)}}>
                                <img src={item.pic} alt="" />
                                <p>{item.name}</p>
                                <span>原价￥{item.salesPrice.value}</span>
                                <p>抢购价￥<span>{(item.salesPrice.value*item.activityTags[0].slice(0,item.activityTags[0].length-1)*0.1).toFixed(2)}</span></p>
                            </div>
                        )
                    })
                }
            </div>
        );
    }
}

export default withRouter(Recommend);